package servlet;

import dao.EquipmentDaoImpl;
import utils.string.session.SessionStringUtil;
import vo.Equipment;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

public class UpdateEquipmentServlet extends HttpServlet {
    //该对象是为了更改设备里的数据
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        EquipmentDaoImpl equipmentDao = new EquipmentDaoImpl();
        int equipmentId = Integer.parseInt(req.getParameter("equipmentId"));
        int updateEquipmentNum = Integer.parseInt(req.getParameter("updateEquipmentNumber"));
        String euquipmentName = req.getParameter("equipmentName");
        Equipment equipment = new Equipment();
        equipment.setEquip_name(euquipmentName);
        equipment.setEquip_num(updateEquipmentNum);
        equipmentDao.updateById(equipment,equipmentId);

        HashMap equipments = equipmentDao.selectAll();
        req.getSession().setAttribute(SessionStringUtil.ALL_UNUSED_EQUIPMENTS,equipments);
        resp.sendRedirect("/equipmentManager_war_explode/manageAllEquipments.jsp");
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("/equipmentManager_war_explode/manageAllEquipments.jsp");
    }
}
